<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <canvas id="canvas" style="border: 1px solid #aaa; display: block; margin: 50px auto;">
        当前浏览器不支持Canvas，请更换浏览器
    </canvas>
    <script>
        window.onload = function () {
            var canvas = document.getElementById("canvas");

            canvas.width = 800;
            canvas.height = 800;

            var context = canvas.getContext("2d");

            context.lineWidth = 10;
            context.beginPath();    //开始一段全新的路径
            context.moveTo(100, 200);
            context.lineTo(300, 400);
            context.lineTo(100, 600);
            context.strokeStyle = 'red';    //线条样式
            context.stroke();   //完成线条

            context.beginPath();
            context.moveTo(300, 200);
            context.lineTo(500, 400);
            context.lineTo(300, 600);
            context.strokeStyle = 'green';
            context.stroke();

            context.beginPath();
            context.moveTo(500, 200);
            context.lineTo(700, 400);
            context.lineTo(500, 600);
            context.strokeStyle = '#058';
            context.stroke();
        }
    </script>
</body>
</html>